/**
 * 
 */
package wpmp.extjs3.data;

import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;

import wcommons.lang.JsonUtils;

/**
 * JsonStore.load() return this data style
 * 
 * <pre>
 * jsonStore.load({
 * });
 * </pre>
 * 
 * @author Wayne.Wang<5waynewang@gmail.com>
 * @since 5:59:16 PM Dec 19, 2012
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public class JsonStore<T> implements Serializable {

	private static final long serialVersionUID = 1L;

	private int total;

	private Collection<T> records;

	public static final JsonStore EMPTY = new JsonStore(Collections.EMPTY_LIST);

	public JsonStore() {
	}

	public JsonStore(Collection<T> records) {
		if (records != null) {
			this.total = records.size();
		}
		this.records = records;
	}

	public JsonStore(int total, Collection<T> records) {
		this.total = total;
		this.records = records;
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public Collection<T> getRecords() {
		return records;
	}

	public void setRecords(Collection<T> records) {
		this.records = records;
	}

	@Override
	public String toString() {
		return JsonUtils.toJSONString(this);
	}

	public String toJSONString() {
		return this.toString();
	}
}
